//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ExponentialSplinesFitting.h"
using namespace Cephei::QL::Termstructures::Yield;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (Microsoft::FSharp::Core::FSharpOption<Boolean>^ constrainAtZero) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phExponentialSplinesFitting = NULL;
#endif
        bool _constrainAtZero = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (constrainAtZero) ? (bool)ValueHelper::Convert (constrainAtZero->Value) : true); //4
        _ppExponentialSplinesFitting = new boost::shared_ptr<QuantLib::ExponentialSplinesFitting> (new QuantLib::ExponentialSplinesFitting ( _constrainAtZero ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (boost::shared_ptr<QuantLib::ExponentialSplinesFitting>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phExponentialSplinesFitting = NULL;
#endif
	_ppExponentialSplinesFitting = &childNative;
    
}
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (QuantLib::ExponentialSplinesFitting& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phExponentialSplinesFitting = NULL;
#endif
	_ppExponentialSplinesFitting = new boost::shared_ptr<QuantLib::ExponentialSplinesFitting> (&childNative);
    
    _ExponentialSplinesFittingOwner = owner;
    
}

Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (CExponentialSplinesFitting^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phExponentialSplinesFitting = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppExponentialSplinesFitting = new boost::shared_ptr<QuantLib::ExponentialSplinesFitting> (copy->GetShared());
        
    }
}
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phExponentialSplinesFitting = NULL;
#endif
	if (!t->IsSubclassOf(CExponentialSplinesFitting::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (QuantLib::Handle<QuantLib::ExponentialSplinesFitting>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phExponentialSplinesFitting = &childNative;
	_ppExponentialSplinesFitting = &static_cast<boost::shared_ptr<QuantLib::ExponentialSplinesFitting>>(childNative.currentLink());
    
    _ExponentialSplinesFittingOwner = owner;
}
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (QuantLib::Handle<QuantLib::ExponentialSplinesFitting> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phExponentialSplinesFitting = &childNative;
	_ppExponentialSplinesFitting = &static_cast<boost::shared_ptr<QuantLib::ExponentialSplinesFitting>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::CExponentialSplinesFitting (QuantLib::ExponentialSplinesFitting childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phExponentialSplinesFitting = NULL;
#endif
	_ppExponentialSplinesFitting = new boost::shared_ptr<QuantLib::ExponentialSplinesFitting> (new QuantLib::ExponentialSplinesFitting (childNative));
    
}
#endif

Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::~CExponentialSplinesFitting ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppExponentialSplinesFitting != NULL)
    {
	    delete _ppExponentialSplinesFitting;
        _ppExponentialSplinesFitting = NULL;
    }
}
Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::!CExponentialSplinesFitting ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppExponentialSplinesFitting != NULL)
    {
	    delete _ppExponentialSplinesFitting;
    }
}
QuantLib::ExponentialSplinesFitting& Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::GetReference ()
{
    if (_ppExponentialSplinesFitting == NULL) throw gcnew NativeNullException ();
	return **_ppExponentialSplinesFitting;
}
boost::shared_ptr<QuantLib::ExponentialSplinesFitting>& Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::GetShared ()
{
    if (_ppExponentialSplinesFitting == NULL) throw gcnew NativeNullException ();
	return *_ppExponentialSplinesFitting;
}
QuantLib::ExponentialSplinesFitting* Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::GetPointer ()
{
    if (_ppExponentialSplinesFitting == NULL) throw gcnew NativeNullException ();
	return &**_ppExponentialSplinesFitting;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ExponentialSplinesFitting>& Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::GetHandle ()
{
	if (_phExponentialSplinesFitting == NULL)
	{
		_phExponentialSplinesFitting = new Handle<QuantLib::ExponentialSplinesFitting> (*_ppExponentialSplinesFitting);
	}
	return *_phExponentialSplinesFitting;
}
#endif
bool Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting::HasNative () 
{
	return (_ppExponentialSplinesFitting != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Termstructures::Yield::IExponentialSplinesFitting^ Cephei::QL::Termstructures::Yield::CExponentialSplinesFitting_Factory::Create (Microsoft::FSharp::Core::FSharpOption<Boolean>^ constrainAtZero)
{
    return gcnew CExponentialSplinesFitting ( constrainAtZero);
}
